package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import xw.qxypt.common.utils.BaseTree;
import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpEquipmentEntity;
import xw.qxypt.modules.baseinfo.service.LhpEquipmentService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;
import xw.qxypt.modules.sys.shiro.ShiroUtils;


/**
 * 设备管理
 *
 * @author xw
 * @email 
 * @date 2019-11-28 16:38:08
 */
@RestController
@RequestMapping("baseinfo/lhpequipment")
public class LhpEquipmentController {
    @Autowired
    private LhpEquipmentService lhpEquipmentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("baseinfo:lhpequipment:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpEquipmentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhpequipment:info")
    public R info(@PathVariable("id") String id){
        LhpEquipmentEntity lhpEquipment = lhpEquipmentService.getById(id);

        return R.ok().put("lhpEquipment", lhpEquipment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhpequipment:save")
    public R save(@RequestBody LhpEquipmentEntity lhpEquipment){
        lhpEquipmentService.save(lhpEquipment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhpequipment:update")
    public R update(@RequestBody LhpEquipmentEntity lhpEquipment){
        ValidatorUtils.validateEntity(lhpEquipment);
        lhpEquipmentService.updateById(lhpEquipment);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhpequipment:delete")
    public R delete(@RequestBody String[] ids){
        lhpEquipmentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 设备树
     */
    @RequestMapping("/equipmentTree")

    public List<BaseTree> equipmentTree(){

        return lhpEquipmentService.equipmentTree();
    }

    //根据登录用户查询所有设备
    @RequestMapping("/getEquipmentByUserId")
    public R getEquipmentByUserId(){
        List<LhpEquipmentEntity> equipmentList=lhpEquipmentService.getEquipmentByUserId(ShiroUtils.getUserId());
        return R.ok().put("list",equipmentList);
    }
    //根据pointId查询所有设备
    @RequestMapping("/getEqupimentByPointId/{pointId}")
    public R getEqupimentByPointId(@PathVariable("pointId") String pointId){
        List<LhpEquipmentEntity> equipmentList=lhpEquipmentService.getEqupimentByPointId(pointId);
        return R.ok().put("list",equipmentList);
    }

}
